home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / du_lib / test / testevnt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-10  |  5.0 KB  |  149 lines

  1. /* 
  2.     TEST PROGRAM FOR DU_LIB
  3.     ½1994, Data Uncertain Software.
  4.     Written by Craig Graham.
  5. =============================================================================
  6.     This program is implemented just using an event driven model.
  7.     There is a main event loop rather like the normal GEM application
  8.     model, but the events being waited for aren't GEM move, redraw, etc,
  9.     they are things like 'text has been selected, button1 has been clicked
  10.     on, quit, etc'.
  11. =============================================================================
  12. */
  13.  
  14. #include <dulib.h>
  15. #include "test.h"
  16.  
  17. /* Define some codes for events - these are arbitary integer values */
  18.  
  19. #define mev_QUIT        102
  20. #define mev_BUTTON1        103
  21. #define mev_BUTTON2        104
  22. #define mev_SELTEXT        105
  23. #define mev_OPENDIAL    106
  24. #define mev_POPUP        107
  25.  
  26. /*
  27.     This is going to be a custom redraw function.
  28.     Note that as with callbacks, redraw functions are all "short nnnn(void)".
  29.     A redraw should simply draw it's object - the DU_LIB will handle walking
  30.     the rectangle list & setting minimal clip rectangles.
  31. */
  32. short redy()
  33. {
  34.     short x,y,rx,ry;
  35.  
  36.     rx=(cr_clip.g_w/2)-4;    /* GRECT cr_clip contains the dimensions of the obejct we are going to redraw */
  37.     x=cr_clip.g_x+rx+2;
  38.     ry=(cr_clip.g_h/2)-4;
  39.     y=cr_clip.g_y+ry+2;
  40.     
  41.     v_ellipse(x_handle,x,y,rx,ry);    /* x_handle is a vdi screen workstation handle which we can use */
  42.                                     /*  - this workstation was opened by enviroment_initialise();*/
  43.     return 0;
  44. }
  45.  
  46. short main(void)
  47. {
  48.     OBJECT *o;
  49.     event e;
  50.     char b[200];
  51.     short inv[512];
  52.     short s;
  53. /* Setup an array of char*'s to be a popup menu */
  54.     static char *pmenu[6]={"Test Popup","one","two","three","four", "five" };
  55.  
  56. /* Setup an array of char*'s - these will be the entries in the scroll list */
  57.     static char *t[11]={"This is a demo of the",
  58.                         "DU_LIB GUI library for",
  59.                         "Lattice C.", 
  60.                         "----------------------",
  61.                         "Written:[13/10/94]",
  62.                         "By: Craig Graham",
  63.                         "----------------------",
  64.                         "DULIB was written to",
  65.                         "provide a GUI for the",
  66.                         "other Data Uncertain ",
  67.                         "products."};
  68.  
  69. /* We always call the enviroment initialise function first - this will do all the appl_init() stuff */
  70.    
  71.     enviroment_initialise();
  72.  
  73. /* Load in the resource file */
  74.     rsrc_load("TEST.RSC");
  75.  
  76. /* First, lets use the easy way to change text in a dialog */
  77.     set_dialog_text(My_dial, Testtext, "Testing DULIB Library");
  78.  
  79. /* Setup some events */
  80.     Set_object_event(My_menu, Menuquit, mev_QUIT);
  81.     Set_object_event(My_menu, Menuopendialog, mev_OPENDIAL);
  82.     Set_object_event(My_dial, Button1, mev_BUTTON1);
  83.     Set_object_event(My_dial, Button2, mev_BUTTON2);
  84.     Set_object_event(My_dial, Mypopup, mev_POPUP);
  85.  
  86. /* Setup a test custom redraw function - usually you attach these to a box to get something in the box*/
  87.     Set_object_redraw(My_dial, Crbox, &redy);
  88.  
  89. /* Initialise the scrolling list object */
  90.     Set_scroll_list(My_dial, Scrolllist, mev_SELTEXT, t, 11, 4); /* event code = mev_SELTEXT, text from t, number of items in list=11, number of items to display=4*/
  91.  
  92. /* Set a few icon popups up */
  93.     Set_icon_popup(My_dial, Popup1, Gateiconpopup);
  94.     Set_icon_popup(My_dial, Popup2, Gateiconpopup);
  95.  
  96. /* Set up the menu bar*/
  97.     install_menu(My_menu);
  98.  
  99. /* Configure resources to monochrome if we aren't a colour machine.               */
  100. /*  enviroment_initialise() always opens a vdi virtual workstation to the screen, */
  101. /*  with the handle 'x_handle', so I use that for my screen display work.         */
  102.     vq_extnd(x_handle,0,inv);
  103.     if (inv[13]<16)
  104.         rsrc_form2mono(My_dial, 3); /* Convert the dialog into mono if we need to (ie, we don't have 16 colours) */
  105.     
  106. /* Open the dialog */
  107.     activate_dialog(My_dial,"DULIB: EVENTS TEST",DIAL_ROLLUP);
  108.  
  109.     do
  110.     {
  111.         e=WaitEvent();            /* The all important call. This replaces event_multi */
  112.  
  113.         switch (e)
  114.         {
  115.             case mev_SELTEXT:
  116.                 sprintf(b,"[1][ SCROLL TEXT SELECTED : | '%s' | ][ OK ]",t[scroll_selection]);
  117.                 form_alert(1,b);
  118.                 break;
  119.             case mev_OPENDIAL:
  120.                 activate_dialog(My_dial,"DULIB TEST DIALOG",DIAL_ROLLUP);
  121.                 break;
  122.             case mev_BUTTON1:
  123.                 DU_mode(DU_MODE_RIGHT_EQUALS_DOUBLE,TRUE);
  124.                 form_alert(1,"[1][ BUTTON 1 SELECTED | Right Mouse Button now | equals double click ][ OK ]");
  125.                 break;
  126.             case mev_BUTTON2:
  127.                 DU_mode(DU_MODE_RIGHT_EQUALS_DOUBLE,FALSE);
  128.                 form_alert(1,"[1][ Right Mouse Button Ignored | (button 2) | ][ spam? ]");
  129.                 break;
  130.             case mev_POPUP:
  131.                 /* call form_popup(), for 5 items (remember, item 0 is the popup's title line), with no default selection */
  132.                 s=form_popup(My_dial,Mypopup, 5, 0, pmenu);
  133.                 /* set the text in the dialog to show which option was selected from the popup */
  134.                 set_dialog_text(My_dial,Mypopup, pmenu[s]);
  135.                 rsrc_gaddr(0,My_dial,&o);
  136.                 objc_draw(o,Mypopup,1,scrn_x,scrn_y,scrn_w,scrn_h);
  137.                 break;
  138.         }
  139.  
  140.     } while (e!=mev_QUIT);
  141.  
  142.     rsrc_free();
  143.  
  144.     close_down();
  145.  
  146.     return 0;
  147.     
  148. }
  149.